﻿using Meiam.System.Model.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Meiam.System.Interfaces
{
    public class SqlSugarBase<T> where T : class
    {
        /// <summary>
        /// 连接字符串
        /// </summary>
        public string connectionString = string.Empty;

        /// <summary>
        ///
        /// </summary>
        public SqlSugarClient db => GetInstance();


        SqlSugarClient GetInstance()
        {
            var db = new SqlSugarClient(
                new ConnectionConfig
                {
                    ConnectionString = connectionString,
                    DbType = SqlSugar.DbType.MySql,
                    IsAutoCloseConnection = true,
                    InitKeyType = InitKeyType.Attribute
                }
            );
            return db;
        }

        public List<T> Query(string sql)
        {
           return db.Ado.SqlQuery<T>(sql);
        }

    }
}
